package com.oa.datasource;

import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;

import javax.sql.DataSource;
import java.sql.SQLException;

public class DruidDataSourceFactory extends UnpooledDataSourceFactory {

    public DruidDataSourceFactory() {
        // 实例化数据源对象
        // datasource 是来自于父类  DruidDataSource是阿里的实现
        this.dataSource = new DruidDataSource();
    }

    //这个返回的DataSource是标准 每一个连接池都要实现这个接口
    @Override
    public DataSource getDataSource() {
        try {
            ((DruidDataSource)this.dataSource).init();  //初始化druid数据源 不执行配置无法生效
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return this.dataSource;
    }

}
